package thread;

/**
 * Created by Administrator on 2017/7/5.
 */
public class DeadLockDemo {
    private static final String STATIC_A = "A";
    private static final String STATIC_B = "B";
    public void deadLock(){

       Thread t1 =  new Thread(new Runnable() {
           public void run() {
               synchronized (STATIC_A){
                   try {
                       System.out.println("t1:A");
                       Thread.currentThread().sleep(2000);
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
                   synchronized (STATIC_B){
                       System.out.println("t1:B");
                   }
               }
           }
       });

       Thread t2 = new Thread(new Runnable() {
           public void run() {
               synchronized (STATIC_B){
                   System.out.println("t2:B");
                   try {
                       Thread.currentThread().sleep(500);
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
                   synchronized (STATIC_A){
                       System.out.println("t2:A");
                   }
               }
           }
       });
        t1.start();
        t2.start();
    }

    public static void main(String[] args) {
        new DeadLockDemo().deadLock();
    }
}
